package com.jtzc.mcp.weixin.config;

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.jtzc.mcp.weixin.domain.service.WeiXinNoticeService;
import com.jtzc.mcp.weixin.infrastructure.gateway.IWeixinApiService;
import org.springframework.ai.tool.ToolCallbackProvider;
import org.springframework.ai.tool.method.MethodToolCallbackProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.EventListener;
import retrofit2.Retrofit;
import retrofit2.converter.jackson.JacksonConverterFactory;

import java.util.concurrent.TimeUnit;

@Configuration
public class McpCongfig {

    @Bean
    public IWeixinApiService weixinApiService() {
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("https://api.weixin.qq.com/")
                .addConverterFactory(JacksonConverterFactory.create())
                .build();
        return retrofit.create(IWeixinApiService.class);
    }

    @Bean(name = "weixinAccessToken")
    public Cache<String, String> weixinAccessToken() {
        return CacheBuilder.newBuilder()
                .expireAfterWrite(2, TimeUnit.HOURS)
                .build();
    }

    @Bean
    public ToolCallbackProvider weixinTools(WeiXinNoticeService weiXinNoticeService) {
        return MethodToolCallbackProvider.builder().toolObjects(weiXinNoticeService).build();
    }


}
